Skip to content

gh-161366: Fix deadlock with FT GC debug collectables print - #161444

Merged
kumaraditya303 merged 4 commits into
python:mainfrom
johng:ft-gc-debug-collectable-stw
Nov 9, 2026
Merged

kumaraditya303 merged 4 commits into
python:mainfrom
johng:ft-gc-debug-collectable-stw

Conversation

@johng

@johng johng commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

debug printing collectables ran under stop the world in the debug cycle which can deadlock on buffered writer. In debug mode this immediately fails.

We move the debug print to outside of stop the world block inside the needs_resurrection_check so the correct cleanup can run before collection.

debug printing collectables ran under stop the world
in the debug cycle which can deadlock on buffered writer.
In debug mode this immediately.

We move the debug print to outside of stop the world
block inside the `needs_resurrection_check` so the
correct cleanup can run but before collection.

self.assertTrue(C().run())

def test_debug_collectable_python_stderr(self):

@johng johng Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure of precedence with this type of test, it will only be useful in debug mode

Comment thread Python/gc_free_threading.c Outdated
_PyEval_StartTheWorld(interp);

// Print debugging information.
if (FT_ATOMIC_LOAD_INT_RELAXED(interp->gc.debug) & _PyGC_DEBUG_COLLECTABLE) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we hit this code branch always when in debug collectables mode, however this section is after start the world

@johng
johng marked this pull request as ready for review November 5, 2026 21:15
@johng

johng commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

CC @sergey-miryanov @nascheme thanks!

@kumaraditya303 kumaraditya303 changed the title gh-161366: Fix deadlock with FT GC debug collecatables print gh-161366: Fix deadlock with FT GC debug collectables print Nov 9, 2026
@kumaraditya303
kumaraditya303 merged commit 6e9a900 into python:main Nov 9, 2026
60 checks passed
@bedevere-app

bedevere-app Bot commented Nov 14, 2026

Copy link
Copy Markdown

GH-162007 is a backport of this pull request to the 3.15 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants